<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Redis 批处理机制深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            position: relative;
            overflow: hidden;
        }
        
        .hero-gradient::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            padding: 20px;
            overflow-x: auto;
            position: relative;
            font-family: 'Consolas', 'Monaco', monospace;
        }
        
        .code-block::before {
            content: 'JAVA';
            position: absolute;
            top: 10px;
            right: 10px;
            font-size: 12px;
            color: #666;
            background: #2d2d2d;
            padding: 2px 8px;
            border-radius: 4px;
        }
        
        .feature-card {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 30px;
            border-radius: 16px;
            position: relative;
            overflow: hidden;
            transition: all 0.3s ease;
        }
        
        .feature-card:hover {
            transform: scale(1.05);
        }
        
        .feature-card::before {
            content: '';
            position: absolute;
            top: -50%;
            right: -50%;
            width: 200%;
            height: 200%;
            background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
            animation: pulse 3s ease-in-out infinite;
        }
        
        @keyframes pulse {
            0%, 100% { transform: scale(1); opacity: 0.5; }
            50% { transform: scale(1.1); opacity: 0.3; }
        }
        
        .comparison-table {
            background: white;
            border-radius: 12px;
            overflow: hidden;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
        }
        
        .comparison-table th {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 16px;
            text-align: left;
            font-weight: 600;
        }
        
        .comparison-table td {
            padding: 16px;
            border-bottom: 1px solid #f0f0f0;
        }
        
        .comparison-table tr:hover {
            background: #f8f9fa;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 40px 0;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
            border-radius: 12px;
            padding: 24px;
            margin: 20px 0;
            position: relative;
            overflow: hidden;
        }
        
        .highlight-box::before {
            content: '\f0eb';
            font-family: 'Font Awesome 6 Free';
            font-weight: 900;
            position: absolute;
            top: 20px;
            right: 20px;
            font-size: 48px;
            color: rgba(255, 255, 255, 0.3);
        }
        
        .list-item {
            position: relative;
            padding-left: 30px;
            margin-bottom: 12px;
        }
        
        .list-item::before {
            content: '\f00c';
            font-family: 'Font Awesome 6 Free';
            font-weight: 900;
            position: absolute;
            left: 0;
            top: 2px;
            color: #667eea;
        }
        
        .drop-cap {
            float: left;
            font-size: 72px;
            line-height: 60px;
            padding-right: 8px;
            margin-top: -4px;
            font-weight: 700;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-family: 'Noto Serif SC', serif;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-8 relative">
        <div class="max-w-6xl mx-auto relative z-10">
            <h1 class="text-5xl md:text-6xl font-bold mb-6 animate-pulse">
                <i class="fas fa-database mr-4"></i>Redis 批处理机制深度解析
            </h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">探索原生批处理命令与 Pipeline 的性能优化之道</p>
            <div class="flex flex-wrap gap-4">
                <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                    <i class="fas fa-clock mr-2"></i>阅读时间：8分钟
                </span>
                <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                    <i class="fas fa-tag mr-2"></i>Redis 优化
                </span>
                <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                    <i class="fas fa-chart-line mr-2"></i>性能提升
                </span>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-6xl mx-auto px-8 py-12">
        <!-- Introduction Card -->
        <div class="content-card rounded-2xl p-8 mb-12">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">R</span>edis 的原生批处理命令（如 <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">MSET</code> 和 <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">MGET</code>）适用于处理少量的批量操作，并提供了简单易用的接口。Pipeline 则适用于高负载和大规模操作，通过减少网络往返延迟来提高性能。根据具体的应用场景和需求，选择合适的机制可以显著提高 Redis 的操作效率和性能。
            </p>
        </div>

        <!-- Section 1: 原生批处理命令 -->
        <div class="mb-16">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">
                <i class="fas fa-terminal mr-3 text-purple-600"></i>一、原生批处理命令
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div class="content-card rounded-xl p-6">
                    <h3 class="text-xl font-semibold mb-4 text-gray-800">
                        <i class="fas fa-question-circle mr-2 text-purple-500"></i>什么是原生批处理命令？
                    </h3>
                    <p class="text-gray-600 mb-4">
                        原生批处理命令是 Redis 提供的能够一次性处理多个键值对的命令。Redis 的 <code class="bg-gray-100 px-2 py-1 rounded text-sm">MSET</code> 和 <code class="bg-gray-100 px-2 py-1 rounded text-sm">MGET</code> 命令是典型的批处理命令。
                    </p>
                    <div class="bg-gray-50 p-4 rounded-lg">
                        <p class="list-item"><code class="font-mono">MSET</code>：同时设置多个键的值</p>
                        <p class="list-item"><code class="font-mono">MGET</code>：一次性获取多个键的值</p>
                    </div>
                </div>
                
                <div class="code-block">
                    <pre><code>// 批量设置键值对
MSET key1 value1 key2 value2 key3 value3

// 批量获取键值对
MGET key1 key2 key3</code></pre>
                </div>
            </div>

            <div class="grid md:grid-cols-2 gap-8">
                <div class="feature-card">
                    <h4 class="text-2xl font-bold mb-4">
                        <i class="fas fa-shield-alt mr-2"></i>优势
                    </h4>
                    <div class="relative z-10">
                        <p class="mb-3"><i class="fas fa-lock mr-2"></i><strong>原子性</strong>：MSET 命令是原子性的，确保数据的一致性</p>
                        <p><i class="fas fa-magic mr-2"></i><strong>简单易用</strong>：在单个命令中同时处理多个键值对</p>
                    </div>
                </div>
                
                <div class="content-card rounded-xl p-6">
                    <h4 class="text-2xl font-bold mb-4 text-gray-800">
                        <i class="fas fa-exclamation-triangle mr-2 text-orange-500"></i>限制
                    </h4>
                    <p class="mb-3"><strong>请求/响应模型</strong>：每个批处理命令仍然是一个单独的请求/响应周期</p>
                    <p><strong>灵活性</strong>：只适用于 Redis 支持的特定批处理操作</p>
                </div>
            </div>
        </div>

        <!-- Section 2: Pipeline -->
        <div class="mb-16">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">
                <i class="fas fa-stream mr-3 text-purple-600"></i>二、Pipeline
            </h2>
            
            <div class="content-card rounded-xl p-8 mb-8">
                <h3 class="text-xl font-semibold mb-4 text-gray-800">
                    <i class="fas fa-info-circle mr-2 text-purple-500"></i>什么是 Pipeline？
                </h3>
                <p class="text-gray-600 mb-6">
                    Pipeline 是 Redis 客户端提供的一种机制，可以在一个请求中发送多个命令，而不等待每个命令的响应。这种机制允许在网络往返延迟（Round-Trip Time, RTT）期间继续发送命令，从而提高吞吐量。
                </p>
                
                <div class="code-block mb-6">
                    <pre><code>// 使用 Pipeline 批量设置键值对
try (Jedis jedis = new Jedis("localhost")) {
    Pipeline pipeline = jedis.pipelined();
    pipeline.set("key1", "value1");
    pipeline.set("key2", "value2");
    pipeline.set("key3", "value3");
    pipeline.sync();  // 发送所有命令并等待结果
}</code></pre>
                </div>
                
                <p class="text-gray-600">